<!-- 左侧工具条 -->
<template>
<div class="leftTools">
    <ul>
        <li v-for="(tool,index) in tools" :key="index" @click="_toolClick(tool, index)" :style="tool.checked?'background:#1296db;':''">
            <div class="toolgrid" :style="index == tools.length-1?'':'border-bottom: 1px solid #dcdfe6;'">
                <div style="margin:5px 0px 0px 0px;">
                    <img v-if="tool.checked" :src="imgpath + tool.img +'-1.png'" style="width: 30px;">
                    <img v-else :src="imgpath + tool.img +'.png'" style="width: 30px;">
                </div>
                <div style="margin:2px 0px;">
                    <span v-if="tool.checked" style="color:#fff;">{{tool.title}}</span>
                    <span v-else>{{tool.title}}</span>
                </div>
            </div>
        </li>
    </ul>
</div>
</template>

<script>
import * as api from '../../../utils/api_gis'
import * as esriLoader from "esri-loader";
import Pubsub from "pubsub-js";
import MapManager from "../../../core/mapManager";


export default {
    data() {
        return {
            // imgpath: window.location.origin + window.location.pathname + "static/img/lefttools/",
            imgpath: "../../../../static/imgs/lefttools/",
            tools: window.g.Project.leftTools,
            selectTool: null,
            seriesDataChart: null, //用来存放接口获取的饼图数据，切换比例尺不在重复调用接口
        };
    },
    components: {},
    methods: {
        //工具条点击事件
        _toolClick(tool, index) {
            const self = this
            
            //1、按钮互斥
            self.tools.forEach(tt => {
                if(tt.checked && tt.id!=tool.id){
                    self._removeLayer(tt)
                    tt.checked= !tt.checked
                }
            })
            
            //加载、移除（聚合-服务）
            tool.checked = !tool.checked
            self.selectTool = tool
            if (tool.checked) {
                self._addLayer(tool)
                if(tool.id=="存量农房"){
                    Pubsub.publish('iQueryShow', false);//隐藏i查询
                }else{
                    Pubsub.publish('iQueryShow', true);//显示i查询
                }
            } else {
                self._removeLayer(tool)
                if(tool.id=="存量农房"){
                    Pubsub.publish('iQueryShow', true);//显示i查询
                }
            }

        },
        //添加图层
        _addLayer(tool) {
            const self = this
            
            let targetLayers = window.g.MapConfiguration.lifeCircleLayers[tool.id]
            if (!targetLayers) {
                return;
            }

            const addingLayers = [];
            targetLayers.forEach((layerConfig) => {
                let addingLayer = null
                if (layerConfig.layerType == "Tile") {
                    addingLayer = new self.TileLayer({
                        title: layerConfig.basename,
                        id: layerConfig.basename,
                        url: layerConfig.url,
                        resourcesData: layerConfig,
                        maxScale: layerConfig.maxScale !== undefined ? layerConfig.maxScale : 0,
                        minScale: layerConfig.minScale !== undefined ? layerConfig.minScale : 73000,
                    });
                } else if (layerConfig.layerType == "MapImage") {
                    addingLayer = new self.MapImageLayer({
                        title: layerConfig.basename,
                        id: layerConfig.basename,
                        url: layerConfig.url,
                        queryurl: layerConfig.url,
                        resourcesData: layerConfig,
                        maxScale: layerConfig.maxScale !== undefined ? layerConfig.maxScale : 0,
                        minScale: layerConfig.minScale !== undefined ? layerConfig.minScale : 73000,
                        // sublayers: [{
                        //     id: 0,
                        //     visible: true,
                        //     definitionExpression: "1=1",
                        // }],
                    });
                } else if (layerConfig.layerType == "VectorTile") {
                    addingLayer = new self.VectorTileLayer({
                        title: layerConfig.basename,
                        id: layerConfig.basename,
                        url: layerConfig.url,
                        queryurl: layerConfig.urlQuery,
                        resourcesData: layerConfig,
                        maxScale: layerConfig.maxScale !== undefined ? layerConfig.maxScale : 0,
                        minScale: layerConfig.minScale !== undefined ? layerConfig.minScale : 73000,
                    });
                } else {
                    addingLayer = new self.FeatureLayer({
                        title: layerConfig.basename,
                        id: layerConfig.basename,
                        url: layerConfig.url,
                        resourcesData: layerConfig,
                        maxScale: layerConfig.maxScale !== undefined ? layerConfig.maxScale : 0,
                        minScale: layerConfig.minScale !== undefined ? layerConfig.minScale : 73000,
                    });
                }

                addingLayers.push(addingLayer);
            })

            self.mapView.map.addMany(addingLayers);
            self._setLayers()
        },
        //移除图层
        _removeLayer(tool) {
            const self = this
            let targetLayers = window.g.MapConfiguration.lifeCircleLayers[tool.id]
            if (!targetLayers) {
                return;
            }
            targetLayers.forEach(item => {
                if (self.mapView.map.findLayerById(item.basename)) {
                    self.mapView.map.remove(self.mapView.map.findLayerById(item.basename));
                }
            })
            

            self.seriesDataChart = null //清空上一次图表（安全管理）预存的接口结果 
            //清空数值汇总
            if (self.totalLabelLayerSJ) {
                self.totalLabelLayerSJ.removeAll();
            }
            if (self.totalLabelLayerQX) {
                self.totalLabelLayerQX.removeAll();
            }
            // if (self.totalLabelLayerXZ) {
            //     self.totalLabelLayerXZ.removeAll();
            // }
            //2、清空图表汇总
            MapManager.clearMapRenderer();
        },

        //添加聚合图层
        _setLayers() {
            const self = this
            
            let tool = self.selectTool
            self.seriesDataChart = null //清空上一次图表（安全管理）预存的接口结果    

            //1、清空数值汇总
            if (self.totalLabelLayerSJ) {
                self.totalLabelLayerSJ.removeAll();
            }
            if (self.totalLabelLayerQX) {
                self.totalLabelLayerQX.removeAll();
            }
            // if (self.totalLabelLayerXZ) {
            //     self.totalLabelLayerXZ.removeAll();
            // }
            //2、清空图表汇总
            MapManager.clearMapRenderer();

            //获取接口对应的参数
            let params = ""
            switch (tool.id) {
                case "农房审批":
                    params = {
                        "chartId": "3a78044e-9972-217a-4f57-39c08f31d2ef"
                    }
                    break;
                case "农房建设":
                    params = {
                        "chartId": "f8168c6e-488c-45c1-c56e-472bdeacf48d"
                    }
                    break;
                case "存量农房":
                    params = {
                        "chartId": "4c6ac94d-ea98-8ff5-ade9-fdfd1b6g8882",
                        "complexQueryModels": [{
                            "key": "TYPE",
                            "value": "四类重点农房统计"
                        }, {
                            "key": "YEAR",
                            "value": window.g.currentYear
                        }]
                    }
                    break;
                case "农房安全":
                    params = {
                        "chartId": "414102eacf134c8f9a84177e01ece1db",
                        "complexQueryModels": [{
                                "key": "CITYCODE",
                                "value": "330000000000"
                            },
                            {
                                "key": "YEAR",
                                "value": window.g.currentYear
                            },
                            {
                                "key": "TYPE",
                                "value": "安全管理-安全管理-房屋健康度-常态化风险"
                            },
                            {
                                "key": "DATANAME",
                                "value": "'Ⅰ级','Ⅱ级'"
                            }
                        ]
                    }
                    break;
                case "危房改造":
                    params = {
                        "chartId": "78c9ab79449d11ed8a056805cac0b010",
                        "complexQueryModels": [{
                            "key": "CITYCODE",
                            "value": "330000000000"
                        }, {
                            "key": "YEAR",
                            "value": window.g.currentYear
                        }, {
                            "key": "TYPE",
                            "value": "危房改造-动态监测-地图-危房整治"
                        }]
                    }
                    break;
                case "生产经营":
                    params = {
                        "chartId": "b7363e6e19124f8eba589270f8df4d36",
                        "complexQueryModels": [{
                            "key": "CITYCODE",
                            "value": "330000000000"
                        }, {
                            "key": "YEAR",
                            "value": window.g.currentYear
                        }, {
                            "key": "TYPE",
                            "value": "首页-生产经营-房屋数量"
                        }]
                    }
                    break;
                case "视频监控":
                    break;
                case "传感器监测":
                    break;
            }

            if (tool.type && params != "") {
                if (tool.type == "count") {
                    self._setCollectLayers(params)
                } 
                // else if (tool.type == "chart") {
                //     self._setChartLayers(params)
                // }
            }
        },

        //#region ------------添加市级、区县汇总图层--------------
        _setCollectLayers: async function (params) {
            const self = this
            
            const res = await api.getDataByChartSql(params);
            if (res.data.data.seriesData && res.data.data.seriesData.length > 0) {
                //1-1、添加市级 数值汇总
                self.Citys.forEach(city => {
                    let datas = res.data.data.seriesData.filter(tt => {
                        return city.Name == tt.CITYNAME
                    })
                    if (datas.length > 0) {
                        self._setLayer(datas[0], self.totalLabelLayerSJ)
                    }
                })
                //1-2、添加区县 数值汇总
                self.Districts.forEach(city => {
                    let datas = res.data.data.seriesData.filter(tt => {
                        return city.Name == tt.CITYNAME
                    })
                    if (datas.length > 0) {
                        self._setLayer(datas[0], self.totalLabelLayerQX)
                    }
                })
            }
        },
        //根据比例尺，显示市级、区县的数值汇总
        _setLayer(data, totalLabelLayer) {
            const self = this
            
            if (data["CENTERX"] != "" && data["CENTERY"] != "") {
                let geo = new self.Point({
                    x: Number(data["CENTERX"]),
                    y: Number(data["CENTERY"]),
                    spatialReference: self.mapView.spatialReference,
                })
                const g = new self.Graphic({
                    geometry: geo,
                    symbol: {
                        type: "simple-marker",
                        style: "circle",
                        color: "#219CFF",
                        size: 48,
                        outline: {
                            color: "#219CFF",
                            width: 1,
                        },
                    },
                });
                const t1 = new self.Graphic({
                    geometry: geo,
                    symbol: {
                        type: "text",
                        text: data["CITYNAME"],
                        color: "white",
                        haloColor: "#000000",
                        haloSize: "0.5px",
                        font: {
                            family: "Microsoft-YaHei",
                            size: 12,
                        },
                        yoffset: 5,
                        xoffset: 0,
                    },
                });
                const t = new self.Graphic({
                    geometry: geo,
                    symbol: {
                        type: "text",
                        text: data["DATAVALUE"] ? Number(data["DATAVALUE"]) : Number(data["NUM"]),
                        color: "white",
                        haloColor: "#000000",
                        haloSize: "0.5px",
                        font: {
                            family: "Microsoft-YaHei",
                            size: 12,
                        },
                        yoffset: -15,
                        xoffset: 0,
                    },
                });
                totalLabelLayer.addMany([g, t, t1]);
            }

        },
        //#endregion

        //#region ------------添加市级、区县饼图图层(注意：！！！新版没有饼图，暂时屏蔽，，，且新增了掩膜，饼图相关未做掩膜处理)--------------
        // _setChartLayers: async function (params) {
        //     const self = this

        //     const res = await api.getDataByChartSql(params);
        //     if (res.data.data.seriesData && res.data.data.seriesData.length > 0) {
        //         self.seriesDataChart = res.data.data.seriesData //将数值存放起来，只切换比例尺的时候不在重复调用接口等等
        //         self._setChart(res.data.data.seriesData)
        //     }
        // },
        // //根据比例尺，显示市级、区县的饼图汇总
        // _setChart(seriesDataChart) {
        //     const self = this

        //     if (seriesDataChart == null) {
        //         return
        //     }

        //     //1、移除地图上的所有图表
        //     MapManager.clearMapRenderer();

        //     //2、添加显示图表
        //     if (self.mapView.scale > 580000 && self.mapView.scale <= 2310000) {
        //         //2-1、匹配市级地图数据、获取市级经纬度坐标点
        //         let areaDataCitys = []
        //         self.Citys.forEach(city => {
        //             let datas = seriesDataChart.filter(tt => {
        //                 return city.Name == tt.CITYNAME
        //             })
        //             if (datas.length > 0) {
        //                 let areaData = {
        //                     name: city.Name,
        //                     geometry: new self.Point({
        //                         x: Number(city.CENTERX),
        //                         y: Number(city.CENTERY),
        //                         spatialReference: self.mapView.spatialReference,
        //                     }),
        //                     maxScale: 580000,
        //                     minScale: 2310000,
        //                     seriesColors: ["#4bc4fd", "#fbff00"],
        //                     data: [{
        //                             name: datas[0]["NAME"],
        //                             value: Number(datas[0]["NUM"])
        //                         },
        //                         {
        //                             name: datas[1]["NAME"],
        //                             value: Number(datas[1]["NUM"])
        //                         },
        //                     ],
        //                 }
        //                 areaDataCitys.push(areaData)
        //             }
        //         })
        //         MapManager.setMapCharts("pie", areaDataCitys, self.mapView);
        //     } else if (self.mapView.scale <= 580000) {
        //         //2-2、匹配区县地图数据、获取区县经纬度坐标点
        //         let areaDataDistricts = []
        //         self.Districts.forEach(city => {
        //             let datas = seriesDataChart.filter(tt => {
        //                 return city.Name == tt.CITYNAME
        //             })
        //             if (datas.length > 0) {
        //                 // let areaData = self._setChart(datas, city, "totalLabelQX", "区县")
        //                 let areaData = {
        //                     name: city.Name,
        //                     geometry: new self.Point({
        //                         x: Number(city.CENTERX),
        //                         y: Number(city.CENTERY),
        //                         spatialReference: self.mapView.spatialReference,
        //                     }),
        //                     maxScale: 0,
        //                     minScale: 580000,
        //                     seriesColors: ["#4bc4fd", "#fbff00"],
        //                     data: [{
        //                             name: datas[0]["NAME"],
        //                             value: Number(datas[0]["NUM"])
        //                         },
        //                         {
        //                             name: datas[1]["NAME"],
        //                             value: Number(datas[1]["NUM"])
        //                         },
        //                     ],
        //                 }
        //                 areaDataDistricts.push(areaData)
        //             }
        //         })
        //         MapManager.setMapCharts("pie", areaDataDistricts, self.mapView);
        //     }
        // },
        //#endregion

    },
    mounted() {
        const self = this;

        this.Citys = [{
                Code: "441300",
                Name: "杭州市",
                Count: 0,
                CENTERX: 119.52685481,
                CENTERY: 29.87685909,
            },
            {
                Code: "330200",
                Name: "宁波市",
                Count: 0,
                CENTERX: 121.57670537,
                CENTERY: 29.63044257,
            },
            {
                Code: "330300",
                Name: "温州市",
                Count: 0,
                CENTERX: 120.44427123,
                CENTERY: 27.83034691,
            },
            {
                Code: "330400",
                Name: "嘉兴市",
                Count: 0,
                CENTERX: 120.81343867,
                CENTERY: 30.64869538,
            },
            {
                Code: "330500",
                Name: "湖州市",
                Count: 0,
                CENTERX: 119.85833382,
                CENTERY: 30.77897001,
            },
            {
                Code: "330600",
                Name: "绍兴市",
                Count: 0,
                CENTERX: 120.55562739,
                CENTERY: 29.75905452,
            },
            {
                Code: "330700",
                Name: "金华市",
                Count: 0,
                CENTERX: 119.99828721,
                CENTERY: 29.10018642,
            },
            {
                Code: "330800",
                Name: "衢州市",
                Count: 0,
                CENTERX: 118.68221612,
                CENTERY: 28.87087453,
            },
            {
                Code: "330900",
                Name: "舟山市",
                Count: 0,
                CENTERX: 122.36161969,
                CENTERY: 30.21980067,
            },
            {
                Code: "331000",
                Name: "台州市",
                Count: 0,
                CENTERX: 121.11199437,
                CENTERY: 28.68134426,
            },
            {
                Code: "331100",
                Name: "丽水市",
                Count: 0,
                CENTERX: 119.56250219,
                CENTERY: 28.18651807,
            },
        ];
        this.Districts = [{
                Code: "330102",
                Name: "上城区",
                Count: 0,
                CENTERX: 120.17105609,
                CENTERY: 30.22807413,
            },
            {
                Code: "330103",
                Name: "下城区",
                Count: 0,
                CENTERX: 120.1776955,
                CENTERY: 30.30680602,
            },
            {
                Code: "330104",
                Name: "江干区",
                Count: 0,
                CENTERX: 120.29390779,
                CENTERY: 30.31369386,
            },
            {
                Code: "330105",
                Name: "拱墅区",
                Count: 0,
                CENTERX: 120.14628218,
                CENTERY: 30.33983103,
            },
            {
                Code: "330106",
                Name: "西湖区",
                Count: 0,
                CENTERX: 120.08505607,
                CENTERY: 30.21774004,
            },
            {
                Code: "330108",
                Name: "滨江区",
                Count: 0,
                CENTERX: 120.17521631,
                CENTERY: 30.18886244,
            },
            {
                Code: "330109",
                Name: "萧山区",
                Count: 0,
                CENTERX: 120.39325654,
                CENTERY: 30.11941521,
            },
            {
                Code: "330110",
                Name: "余杭区",
                Count: 0,
                CENTERX: 120.00905218,
                CENTERY: 30.36353122,
            },
            {
                Code: "330111",
                Name: "富阳区",
                Count: 0,
                CENTERX: 119.78781417,
                CENTERY: 29.97307859,
            },
            {
                Code: "330112",
                Name: "临安区",
                Count: 0,
                CENTERX: 119.3523127,
                CENTERY: 30.1919109,
            },
            {
                Code: "330122",
                Name: "桐庐县",
                Count: 0,
                CENTERX: 119.57278976,
                CENTERY: 29.84108506,
            },
            {
                Code: "330127",
                Name: "淳安县",
                Count: 0,
                CENTERX: 118.84170947,
                CENTERY: 29.61281895,
            },
            {
                Code: "330182",
                Name: "建德市",
                Count: 0,
                CENTERX: 119.33105736,
                CENTERY: 29.49005883,
            },
            {
                Code: "330203",
                Name: "海曙区",
                Count: 0,
                CENTERX: 121.34578221,
                CENTERY: 29.83805244,
            },
            {
                Code: "330205",
                Name: "江北区",
                Count: 0,
                CENTERX: 121.49666942,
                CENTERY: 29.96764651,
            },
            {
                Code: "330206",
                Name: "北仑区",
                Count: 0,
                CENTERX: 121.90018142,
                CENTERY: 29.85725437,
            },
            {
                Code: "330211",
                Name: "镇海区",
                Count: 0,
                CENTERX: 121.61195918,
                CENTERY: 29.98467741,
            },
            {
                Code: "330212",
                Name: "鄞州区",
                Count: 0,
                CENTERX: 121.67388575,
                CENTERY: 29.76229264,
            },
            {
                Code: "330213",
                Name: "奉化区",
                Count: 0,
                CENTERX: 121.40642197,
                CENTERY: 29.5989822,
            },
            {
                Code: "330225",
                Name: "象山县",
                Count: 0,
                CENTERX: 121.92185401,
                CENTERY: 29.25954085,
            },
            {
                Code: "330226",
                Name: "宁海县",
                Count: 0,
                CENTERX: 121.4876856,
                CENTERY: 29.30901576,
            },
            {
                Code: "330281",
                Name: "余姚市",
                Count: 0,
                CENTERX: 121.14947113,
                CENTERY: 29.99354958,
            },
            {
                Code: "330282",
                Name: "慈溪市",
                Count: 0,
                CENTERX: 121.33586278,
                CENTERY: 30.2224811,
            },
            {
                Code: "330302",
                Name: "鹿城区",
                Count: 0,
                CENTERX: 120.59102401,
                CENTERY: 28.06585327,
            },
            {
                Code: "330303",
                Name: "龙湾区",
                Count: 0,
                CENTERX: 120.80951057,
                CENTERY: 27.88539238,
            },
            {
                Code: "330304",
                Name: "瓯海区",
                Count: 0,
                CENTERX: 120.54066989,
                CENTERY: 27.97692479,
            },
            {
                Code: "330305",
                Name: "洞头区",
                Count: 0,
                CENTERX: 121.04921181,
                CENTERY: 27.855294,
            },
            {
                Code: "330324",
                Name: "永嘉县",
                Count: 0,
                CENTERX: 120.65499439,
                CENTERY: 28.3152083,
            },
            {
                Code: "330326",
                Name: "平阳县",
                Count: 0,
                CENTERX: 120.59982924,
                CENTERY: 27.55998208,
            },
            {
                Code: "330327",
                Name: "苍南县",
                Count: 0,
                CENTERX: 120.45739956,
                CENTERY: 27.32120068,
            },
            {
                Code: "330328",
                Name: "文成县",
                Count: 0,
                CENTERX: 120.0162205,
                CENTERY: 27.77711106,
            },
            {
                Code: "330329",
                Name: "泰顺县",
                Count: 0,
                CENTERX: 119.93279362,
                CENTERY: 27.55552778,
            },
            {
                Code: "330381",
                Name: "瑞安市",
                Count: 0,
                CENTERX: 120.69668222,
                CENTERY: 27.79910197,
            },
            {
                Code: "330382",
                Name: "乐清市",
                Count: 0,
                CENTERX: 121.01748818,
                CENTERY: 28.25523595,
            },
            {
                Code: "330402",
                Name: "南湖区",
                Count: 0,
                CENTERX: 120.81476322,
                CENTERY: 30.72500326,
            },
            {
                Code: "330411",
                Name: "秀洲区",
                Count: 0,
                CENTERX: 120.67383659,
                CENTERY: 30.77804687,
            },
            {
                Code: "330421",
                Name: "嘉善县",
                Count: 0,
                CENTERX: 120.88765648,
                CENTERY: 30.89685141,
            },
            {
                Code: "330424",
                Name: "海盐县",
                Count: 0,
                CENTERX: 120.88566263,
                CENTERY: 30.45580283,
            },
            {
                Code: "330481",
                Name: "海宁市",
                Count: 0,
                CENTERX: 120.5724118,
                CENTERY: 30.42962408,
            },
            {
                Code: "330482",
                Name: "平湖市",
                Count: 0,
                CENTERX: 121.14101902,
                CENTERY: 30.67679493,
            },
            {
                Code: "330483",
                Name: "桐乡市",
                Count: 0,
                CENTERX: 120.47744646,
                CENTERY: 30.63414673,
            },
            {
                Code: "330502",
                Name: "吴兴区",
                Count: 0,
                CENTERX: 120.11459847,
                CENTERY: 30.78825888,
            },
            {
                Code: "330503",
                Name: "南浔区",
                Count: 0,
                CENTERX: 120.27588274,
                CENTERY: 30.77939567,
            },
            {
                Code: "330521",
                Name: "德清县",
                Count: 0,
                CENTERX: 120.04795285,
                CENTERY: 30.56264138,
            },
            {
                Code: "330522",
                Name: "长兴县",
                Count: 0,
                CENTERX: 119.8248872,
                CENTERY: 30.95161034,
            },
            {
                Code: "330523",
                Name: "安吉县",
                Count: 0,
                CENTERX: 119.55895867,
                CENTERY: 30.6250115,
            },
            {
                Code: "330602",
                Name: "越城区",
                Count: 0,
                CENTERX: 120.63758956,
                CENTERY: 30.00227278,
            },
            {
                Code: "330603",
                Name: "柯桥区",
                Count: 0,
                CENTERX: 120.53833966,
                CENTERY: 29.99605892,
            },
            {
                Code: "330604",
                Name: "上虞区",
                Count: 0,
                CENTERX: 120.87177845,
                CENTERY: 30.00601874,
            },
            {
                Code: "330624",
                Name: "新昌县",
                Count: 0,
                CENTERX: 120.96047268,
                CENTERY: 29.39327051,
            },
            {
                Code: "330681",
                Name: "诸暨市",
                Count: 0,
                CENTERX: 120.21024687,
                CENTERY: 29.67111866,
            },
            {
                Code: "330683",
                Name: "嵊州市",
                Count: 0,
                CENTERX: 120.7899561,
                CENTERY: 29.57867023,
            },
            {
                Code: "330802",
                Name: "柯城区",
                Count: 0,
                CENTERX: 118.81669229,
                CENTERY: 29.00102289,
            },
            {
                Code: "330803",
                Name: "衢江区",
                Count: 0,
                CENTERX: 118.92283824,
                CENTERY: 28.92583221,
            },
            {
                Code: "330822",
                Name: "常山县",
                Count: 0,
                CENTERX: 118.50526992,
                CENTERY: 28.99314795,
            },
            {
                Code: "330824",
                Name: "开化县",
                Count: 0,
                CENTERX: 118.32725688,
                CENTERY: 29.20271618,
            },
            {
                Code: "330825",
                Name: "龙游县",
                Count: 0,
                CENTERX: 119.18572066,
                CENTERY: 29.01718635,
            },
            {
                Code: "330881",
                Name: "江山市",
                Count: 0,
                CENTERX: 118.59520214,
                CENTERY: 28.56646485,
            },
            {
                Code: "330902",
                Name: "定海区",
                Count: 0,
                CENTERX: 122.0388494,
                CENTERY: 30.09087431,
            },
            {
                Code: "330903",
                Name: "普陀区",
                Count: 0,
                CENTERX: 122.4689182,
                CENTERY: 29.89515004,
            },
            {
                Code: "330921",
                Name: "岱山县",
                Count: 0,
                CENTERX: 122.1341996,
                CENTERY: 30.36995271,
            },
            {
                Code: "330922",
                Name: "嵊泗县",
                Count: 0,
                CENTERX: 122.36162433,
                CENTERY: 30.64611901,
            },
            {
                Code: "331002",
                Name: "椒江区",
                Count: 0,
                CENTERX: 121.63222909,
                CENTERY: 28.58538965,
            },
            {
                Code: "331003",
                Name: "黄岩区",
                Count: 0,
                CENTERX: 121.07687408,
                CENTERY: 28.60269063,
            },
            {
                Code: "331004",
                Name: "路桥区",
                Count: 0,
                CENTERX: 121.47728582,
                CENTERY: 28.54967395,
            },
            {
                Code: "331022",
                Name: "三门县",
                Count: 0,
                CENTERX: 121.50321667,
                CENTERY: 29.02095939,
            },
            {
                Code: "331023",
                Name: "天台县",
                Count: 0,
                CENTERX: 120.97264243,
                CENTERY: 29.15050353,
            },
            {
                Code: "331024",
                Name: "仙居县",
                Count: 0,
                CENTERX: 120.60878077,
                CENTERY: 28.7327215,
            },
            {
                Code: "331081",
                Name: "温岭市",
                Count: 0,
                CENTERX: 121.45032965,
                CENTERY: 28.37162495,
            },
            {
                Code: "331082",
                Name: "临海市",
                Count: 0,
                CENTERX: 121.38078111,
                CENTERY: 28.85539412,
            },
            {
                Code: "331083",
                Name: "玉环市",
                Count: 0,
                CENTERX: 121.32618852,
                CENTERY: 28.16969184,
            },
            {
                Code: "331102",
                Name: "莲都区",
                Count: 0,
                CENTERX: 119.87692944,
                CENTERY: 28.41309624,
            },
            {
                Code: "331121",
                Name: "青田县",
                Count: 0,
                CENTERX: 120.11540768,
                CENTERY: 28.21014781,
            },
            {
                Code: "331122",
                Name: "缙云县",
                Count: 0,
                CENTERX: 120.14402274,
                CENTERY: 28.6819916,
            },
            {
                Code: "331123",
                Name: "遂昌县",
                Count: 0,
                CENTERX: 119.10353261,
                CENTERY: 28.51412782,
            },
            {
                Code: "331124",
                Name: "松阳县",
                Count: 0,
                CENTERX: 119.43829582,
                CENTERY: 28.42596525,
            },
            {
                Code: "331125",
                Name: "云和县",
                Count: 0,
                CENTERX: 119.54287819,
                CENTERY: 28.10554995,
            },
            {
                Code: "331126",
                Name: "庆元县",
                Count: 0,
                CENTERX: 119.16513271,
                CENTERY: 27.64017049,
            },
            {
                Code: "331127",
                Name: "景宁畲族自治县",
                Count: 0,
                CENTERX: 119.60186121,
                CENTERY: 27.9150742,
            },
            {
                Code: "331181",
                Name: "龙泉市",
                Count: 0,
                CENTERX: 119.06613411,
                CENTERY: 28.02412373,
            },
            {
                Code: "330702",
                Name: "婺城区",
                Count: 0,
                CENTERX: 119.5331155,
                CENTERY: 28.99170157,
            },
            {
                Code: "330703",
                Name: "金东区",
                Count: 0,
                CENTERX: 119.7978485,
                CENTERY: 29.15056766,
            },
            {
                Code: "330723",
                Name: "武义县",
                Count: 0,
                CENTERX: 119.71119321,
                CENTERY: 28.78626312,
            },
            {
                Code: "330726",
                Name: "浦江县",
                Count: 0,
                CENTERX: 119.9019972,
                CENTERY: 29.51892861,
            },
            {
                Code: "330727",
                Name: "磐安县",
                Count: 0,
                CENTERX: 120.53914722,
                CENTERY: 29.07638705,
            },
            {
                Code: "330781",
                Name: "兰溪市",
                Count: 0,
                CENTERX: 119.55324427,
                CENTERY: 29.26587656,
            },
            {
                Code: "330782",
                Name: "义乌市",
                Count: 0,
                CENTERX: 120.04977001,
                CENTERY: 29.29759408,
            },
            {
                Code: "330783",
                Name: "东阳市",
                Count: 0,
                CENTERX: 120.40346714,
                CENTERY: 29.23376479,
            },
            {
                Code: "330784",
                Name: "永康市",
                Count: 0,
                CENTERX: 120.11785531,
                CENTERY: 28.93385472,
            },
        ];

        MapManager.getMapViewByIDAsy("mainMap").then((mapView) => {
            self.mapView = mapView;
            esriLoader
                .loadModules([
                    "esri/layers/VectorTileLayer",
                    "esri/layers/MapImageLayer",
                    "esri/layers/TileLayer",
                    "esri/layers/FeatureLayer",
                    "esri/layers/GraphicsLayer",
                    "esri/Graphic",
                    "esri/geometry/Point",
                    "esri/geometry/Polyline",
                    "esri/geometry/Polygon",
                    "esri/core/watchUtils",
                ])
                .then(
                    ([
                        VectorTileLayer,
                        MapImageLayer,
                        TileLayer,
                        FeatureLayer,
                        GraphicsLayer,
                        Graphic,
                        Point,
                        Polyline,
                        Polygon,
                        watchUtils,
                    ]) => {
                        self.VectorTileLayer = VectorTileLayer;
                        self.MapImageLayer = MapImageLayer;
                        self.TileLayer = TileLayer;
                        self.FeatureLayer = FeatureLayer;
                        self.GraphicsLayer = GraphicsLayer;
                        self.Graphic = Graphic;
                        self.Point = Point;
                        self.Polyline = Polyline;
                        self.Polygon = Polygon;
                        self.watchUtils = watchUtils;
                        
                        //市级
                        self.totalLabelLayerSJ = new self.GraphicsLayer({
                            id: "totalLabelSJ",
                            title: "totalLabelSJ",
                            spatialReference: self.mapView.spatialReference,
                            maxScale: 580000,
                        });
                        //区县
                        self.totalLabelLayerQX = new self.GraphicsLayer({
                            id: "totalLabelQX",
                            title: "totalLabelQX",
                            spatialReference: self.mapView.spatialReference,
                            maxScale: 240000,
                            minScale: 580000,
                        });
                        //乡镇
                        // self.totalLabelLayerXZ = new self.GraphicsLayer({
                        //     id: "totalLabelXZ",
                        //     title: "totalLabelXZ",
                        //     spatialReference: self.mapView.spatialReference,
                        //     maxScale: 145000,
                        //     minScale: 580000 
                        // });
                        self.mapView.map.addMany([self.totalLabelLayerSJ, self.totalLabelLayerQX])

                        //遮罩图层置顶
                        let zhezhaoLayer = MapManager.getLayerFromID(self.mapView, "xzqhGraphicsLayer")
                        if(zhezhaoLayer){ //省级没有遮罩
                            self.mapView.map.reorder(zhezhaoLayer, self.mapView.map.allLayers.items.length);
                        }                        
                        
                        self.extentHandler = watchUtils.watch(self.mapView, "stationary",
                            (e) => {
                                if(self.selectTool){
                                    if( self.selectTool.id == "农房安全"){
                                        //1、图表市级、区县的切换
                                        self._setChart(self.seriesDataChart)
                                    }
                                }
                        })

                    }
                );
        });
    },
    beforeUpdate() {},
}
</script>

<style scoped>
.leftTools {
    position: fixed;
    left: 10px;
    top: 15vh;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0px 6px 10px 0px rgba(0, 0, 0, 0.23);
}

.leftTools ul {
    display: contents;
}

.leftTools li {
    background: #fff;
    text-align: center;
    font-size: 12px;
    cursor: pointer;
}

.leftTools .toolgrid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    grid-gap: 5px;
    margin: auto 4px;
    
}
</style>
